<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2022-11-05 16:25:14
 * @Last Modified time: 2022-12-05 13:43:28
 */
namespace app\common\dao\system;
use frank\base\BaseDao;
use app\common\model\system\AdminModel;

/**
 * Class AdminDao
 * @package app\dao\system
 */
class AdminDao extends \frank\base\BaseDao
{
    protected function setModel(): string
    {
        return AdminModel::class;
    }

    /**
     * 用管理员名查找管理员信息
     */
    public function accountByAdmin(string $account)
    {
        return $this->search(['account' => $account, 'delete_time' => 0, 'status' => 1])->find();
    }

    /**
     * 当前账号是否可用
     */
    public function isAccountUsable(string $account, int $id)
    {
        return $this->search(['account' => $account, 'delete_time' => 0])->where('id', '<>', $id)->count();
    }

    /**
     * 获取adminid
     */
    public function getAdminIds(int $level)
    {
        return $this->getModel()->where('level', '>=', $level)->column('id', 'id');
    }

    /**
     * 获取低于等级的管理员名称和id
     */
    public function getOrdAdmin(string $field = 'real_name,id', int $level = 0)
    {
        return $this->getModel()->where('level', '>=', $level)->field($field)->select()->toArray();
    }

    /**
     * 条件获取管理员数据
     */
    public function getInfo($where)
    {
        return $this->getModel()->where($where)->find();
    }
}

